package com.jackrain.nea.omslocal.conf;

import com.jackrain.nea.omslocal.service.GetTableCloumnsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * @Discription: 程序启动自动加载维护的表结构字段
 * Created with IntelliJ IDEA.
 * @Author cs
 * @Date 2017/5/22 15:36
 */
@Component
@Slf4j
@Order(1)
public class LoadCloumnsConfig implements CommandLineRunner {

    // 新增表字段map
    public static Map insertcolsmap = new HashMap();
    // 更新表字段map
    public static Map updatecolsmap = new HashMap();
    // 维护库存异动表字段map
    public static Map qutycolsmap = new HashMap();
    // 维护淘宝店铺会员字段 map
    public static Map menbercolsmap = new HashMap();
    // 维护库存异常表字段 map
    public static Map qtyerrmsp = new HashMap();
    // 维护同步订单状态表字段
    public static Map ordstatusmap = new HashMap();

    @Autowired
    private GetTableCloumnsService getTableCloumnsService;

    @Override
    public void run(String... strings) throws Exception {

        int code = getTableCloumnsService.getTableCloumns();
        log.debug(insertcolsmap.values().toString());
        log.debug(updatecolsmap.values().toString());
        log.debug(qutycolsmap.values().toString());
        log.debug(menbercolsmap.values().toString());
        log.debug(qtyerrmsp.values().toString());
        log.debug(ordstatusmap.values().toString());
        if (code != 0) {
            // 查询系统表结构
            //getTableCloumnsService.queryCloumns();
            log.debug("获取表字段错误,系统退出中");
            System.exit(0);
        }
    }


    public static Map getInsertcolsmap() {
        return insertcolsmap;
    }

    public static Map getUpdatecolsmap() {
        return updatecolsmap;
    }

    public static void setInsertcolsmap(Map insertmap) {
        LoadCloumnsConfig.insertcolsmap.putAll(insertmap);
    }

    public static void setUpdatecolsmap(Map updatemap) {
        LoadCloumnsConfig.updatecolsmap.putAll(updatemap);
    }


}
